<html xmlns:th="http://www.thymeleaf.org" lang="en">
<head>
    <title>修改密码</title>
    <div th:include="common :: css"></div>
    <style>
        .layui-form-item .layui-input-company {width: auto;padding-right: 10px;line-height: 38px;}
    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <div class="layui-form layuimini-form">
            <div class="layui-form-item">
                <label class="layui-form-label required">用户名</label>
                <div class="layui-input-block">
                    <input type="text" name="account"  lay-reqtext="用户名不能为空" placeholder="请输入用户名" disabled="" th:value="${session.bean.getAccount()}"  class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label required">旧的密码</label>
                <div class="layui-input-block">
                    <input type="password" id="oldPassword" name="oldPassword" lay-verify="required|oldPassword" lay-reqtext="旧的密码不能为空" placeholder="请输入旧的密码"  class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label required">新的密码</label>
                <div class="layui-input-block">
                    <input type="password" id="newPassword" name="newPassword" lay-verify="required|password" lay-reqtext="新的密码不能为空" placeholder="请输入新的密码"  class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label required">确认密码</label>
                <div class="layui-input-block">
                    <input type="password" id="newPassword1" name="newPassword1" lay-verify="required|password" lay-reqtext="新的密码不能为空" placeholder="请输入新的密码" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
                </div>
            </div>
        </div>
    </div>
</div>
<div th:include="common :: js"></div>
<script th:inline="javascript">
    layui.use(['form','miniTab'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;




        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var flag = true;
            var oldPassword = document.getElementById('oldPassword').value;
            var value = [[${session.bean.password}]];
            var newPassword = document.getElementById('newPassword').value;
            var newPassword1 = document.getElementById('newPassword1').value;
            // layer.msg(value);
            if(oldPassword !== value || newPassword !== newPassword1) {
                layer.msg('旧密码输入有误或两次密码输入不一致...');
                flag = false;
            }else {
                flag = true;
            }if(flag){
                // layer.msg('输入信息无误！');
                var index = layer.alert(JSON.stringify(data.field), {
                    title: '最终的提交信息'
                }, function () {
                    //使用Jquery的ajax提交数据
                    $.post("/user/consumer/changePassword",data.field,function (data) {
                        console.log(data);
                    });
                    // 关闭弹出层
                    layer.close(index);
                    var iframeIndex = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(iframeIndex);

                });
                return false;
            }
        });


        //添加校验
        form.verify({
            password: [
                /^[\S]{6,12}$/
                ,'密码必须6到12位，且不能出现空格'
            ],
            oldPassword:[
                /^[\S]{6,12}$/
                ,'密码必须6到12位，且不能出现空格'
            ]

        });
    });
</script>
</body>
</html>